package entity.establishment;

import entity.tta.StakeholderDataModel;
import entity.tx.Advertisement;
import entity.tx.Category;
import entity.tx.GroupBuyingItem;
import entity.tx.PointsPurchaseRecord;
import entity.tx.StakeholderBill;
import entity.tx.StakeholderTier;
import java.util.List;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;

/**
 *
 * @author TWD
 */
@Entity
public class Stakeholder implements Serializable {

    //PRIMARY KEY
    //---------------------------------------------------------------------------------------------------------------------
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO) 
    private Long id;
    //---------------------------------------------------------------------------------------------------------------------
    
    @Column(unique=true, length=255)
    private String name; 
    
    @OneToOne(cascade = {CascadeType.PERSIST})
    private Category category; 
    private String address, phoneNo, postalCode; //Data fields used by CM team
    private Integer loyaltyPoints;
    private boolean purchaseBI;
    private boolean isActivated;
    
    
    @ManyToOne(cascade = {CascadeType.PERSIST})
    private StakeholderTier stakeholderTier;
    //private List<RepresentativeEntity> representative;

    
    @OneToMany(cascade = {CascadeType.ALL}, mappedBy = "stakeholder")
    private List<Advertisement> advertisement;
    
    @OneToMany(cascade = {CascadeType.ALL})
    private List<StakeholderBill> stakeholderBill;
    
    @OneToMany(cascade = {CascadeType.ALL}, mappedBy = "stakeholder")
    private List<GroupBuyingItem> groupon;
    
    @OneToOne(cascade = {CascadeType.ALL})
    private StakeholderDataModel dataModel; 
    
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Calendar createTime;
    
    @OneToMany (cascade={CascadeType.ALL})
    private List<PointsPurchaseRecord> pointsPurchaseLog = new ArrayList<PointsPurchaseRecord>();
      
    
    public boolean create(String name, Integer loyaltyPoints, StakeholderTier stakeholderTier, String email){
        
        try{
            this.name = name;
            this.loyaltyPoints = loyaltyPoints;
            this.setStakeholderTier(stakeholderTier);
            this.dataModel = new StakeholderDataModel(); 
            return true;

        } catch (Exception ex) {
            return false;
        }
    }

    public void addBill(StakeholderBill billToAdd) {
        stakeholderBill.add(billToAdd);
    }

    public void addGroupBuyingItem(GroupBuyingItem gbi) {
        this.groupon.add(gbi);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getLoyaltyPoints() {
        return loyaltyPoints;
    }

    public void setLoyaltyPoints(Integer loyaltyPoints) {
        this.loyaltyPoints = loyaltyPoints;
    }

    public List<StakeholderBill> getStakeholderBill() {
        return stakeholderBill;
    }

    public void setStakeholderBill(List<StakeholderBill> stakeholderBill) {
        this.setStakeholderBill(stakeholderBill);
    }

    public StakeholderTier getStakeholderTier() {
        return stakeholderTier;
    }

    public void setStakeholderTier(StakeholderTier stakeholderTier) {
        this.stakeholderTier = stakeholderTier;
    }

    public List<Advertisement> getAdvertisement() {
        return advertisement;
    }

    public void setAdvertisement(List<Advertisement> Advertisement) {
        this.advertisement = Advertisement;
    }

    public List<GroupBuyingItem> getGroupon() {
        return groupon;
    }

    public void setGroupon(List<GroupBuyingItem> groupon) {
        this.groupon = groupon;
    }

    public boolean isPurchaseBI() {
        return purchaseBI;
    }

    public void setPurchaseBI(boolean purchaseBI) {
        this.purchaseBI = purchaseBI;
    }

    public StakeholderDataModel getDataModel() {
        return dataModel;
    }

    public void setDataModel(StakeholderDataModel dataModel) {
        this.dataModel = dataModel;
    }

    /**
     * @return the pointsPurchaseLog
     */
    public List<PointsPurchaseRecord> getPointsPurchaseLog() {
        return pointsPurchaseLog;
    }

    /**
     * @param pointsPurchaseLog the pointsPurchaseLog to set
     */
    public void setPointsPurchaseLog(List<PointsPurchaseRecord> pointsPurchaseLog) {
        this.pointsPurchaseLog = pointsPurchaseLog;
    }

    /**
     * @return the createTime
     */
    public Calendar getCreateTime() {
        return createTime;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Calendar createTime) {
        this.createTime = createTime;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the category
     */
    public Category getCategory() {
        return category;
    }

    /**
     * @param category the category to set
     */
    public void setCategory(Category category) {
        this.category = category;
    }

    /**
     * @return the address
     */
    public String getAddress() {
        return address;
    }

    /**
     * @param address the address to set
     */
    public void setAddress(String address) {
        this.address = address;
    }

    /**
     * @return the phoneNo
     */
    public String getPhoneNo() {
        return phoneNo;
    }

    /**
     * @param phoneNo the phoneNo to set
     */
    public void setPhoneNo(String phoneNo) {
        this.phoneNo = phoneNo;
    }

    /**
     * @return the postalCode
     */
    public String getPostalCode() {
        return postalCode;
    }

    /**
     * @param postalCode the postalCode to set
     */
    public void setPostalCode(String postalCode) {
        this.postalCode = postalCode;
    }

    /**
     * @return the isActivated
     */
    public boolean isIsActivated() {
        return isActivated;
    }

    /**
     * @param isActivated the isActivated to set
     */
    public void setIsActivated(boolean isActivated) {
        this.isActivated = isActivated;
    }
    
    
    

}
